




import subprocess

# 调用 Windows 命令
result = subprocess.run(['dir', '/a'], capture_output=True, text=True, shell=True)

ip = "10.0.0.1"
# 调用 Bash 脚本
cmd = "kubectl get pods -o wide --namespace=k8s-test | grep "+ip+" | awk '{print $1}'"
print("cmd",cmd)
    
result = subprocess.run(['kubectl', 
                         'get',
                         'pods',
                         '-o',
                         'wide',
                         '--namespace=k8s-test',
                         '|',
                         'grep',
                         f'{ip}',
                         '|',
                         'awk',
                         "'{print }'"
                         ], capture_output=True, text=True)

# 获取标准输出
stdout = result.stdout
print("Standard Output:", stdout)

# 获取标准错误
stderr = result.stderr
print("Standard Error:", stderr)

# 获取返回值
return_code = result.returncode
print("Return Code:", return_code)